#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
int T,L,V,n,m,ctl,ans;
int d[N],v[N],a[N],p[N];
bool c[N];
double x[N];
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    for(int k=1;k<=T;k++){
        ans=0; ctl=0;
        scanf("%d%d%d%d",&n,&m,&L,&V);
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&d[i],&v[i],&a[i]);
            if(v[i]>V) ans++;
        }
        for(int i=1;i<=m;i++){
            scanf("%d",&p[i]);
        }
        printf("%d %d\n",ans,m-(ans?1:0));
//        printf("%d %d",ctl,ans);
//        else if(ctl==2){
//
//        }
    }
    return 0;
}
